﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;

namespace pufflesweb.admin
{
    public partial class Ahelpadd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            PModel.Help help = new PModel.Help();

            if (hname.Text.Trim() == "")
            {
                MessageBox.Show("救助狗不能为空", "提示");
            }
            else if (hage.Text.Trim() == "")
            {
                MessageBox.Show("年龄不能为空", "提示");
            }
            else if (htext.Text.Trim() == "")
            {
                MessageBox.Show("详情不能为空", "提示");
            }
            else if (hstate.Text.Trim() == "")
            {
                MessageBox.Show("健康状态不能为空", "提示");
            }
            else if (hvaccine.Text.Trim() == "")
            {
                MessageBox.Show("疫苗注射情况不能为空", "提示");
            }
            else
            {
                //if (PBLL.Admin.Search(this.aid.Text) == false)
                //{
                //    MessageBox.Show("工号已存在", "提示");
                //}
                //else
                //{
                    help.Hage = int.Parse(this.hage.Text.Trim());
                    help.Hsex = int.Parse(this.hsex.Text.Trim());
                    help.Htext = this.htext.Text.Trim();
                    help.Hname = this.hname.Text.Trim();
                    help.Hstate = int.Parse(this.hstate.Text.Trim());
                    help.Hvaccine = int.Parse(this.hvaccine.Text.Trim());
                   if (himage.HasFile)
                  {
                    string filename = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + Path.GetExtension(himage.FileName);
                    string filePath = "~/images/helpimg/" + filename;
                    himage.SaveAs(MapPath(filePath));
                    help.Himage = filename;
                   }
                //Response.Redirect("index.aspx");
                if (PBLL.Help.add(help))
                    {
                        PF.JsHelper.AlertAndParentUrl("添加成功", "main.aspx");
                    }
                    else
                    {
                        PF.JsHelper.AlertAndParentUrl("添加失败，请重新输入", "Ahelpadd.aspx");
                    }
                

            }
        }
    }
}